// pages/salesclerk/salesclerk.js
var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    stroeId: '',
    list: [],
    statusd: 1,
    isInput: false
  },
  onLoad: function(options) {
    var _ = this
    _.onStore()
  },
  addSalesclerk: function(e) {
    var _this = this,
      id = e.currentTarget.id
    if (id == 0) {
      wx.navigateTo({
        url: '../salesclerkadd/salesclerkadd',
      })
      return false
      _this.setData({
        isInput: true
      })
    } else if (id == 2) {
      _this.setData({
        isInput: false
      })
    } else if (id == 1) {
      let url = app.link.store_users + wx.getStorageSync('store') + '.st',
        data = {
          phone_number: _this.data.phone_number
        }
      com.link(url, data, function(rep) {
        console.log(rep);
        if (rep.data.response.user != null && rep.data.state == true) {
          wx.showToast({
            title: '添加成功',
            icon: 'success'
          })
          _this.setData({
            isInput: false,
            phone_number: ''
          })
        } else if (rep.data.response.user == null && rep.data.state == true) {
          wx.hideToast()
          _this.setData({
            isInput: false,
            phone_number: ''
          })
          wx.showModal({
            title: '温馨提示',
            content: '暂无店员信息,是否去添加？',
            success(r) {
              if (r.confirm) {
                wx.navigateTo({
                  url: '../salesclerkadd/salesclerkadd',
                })
              }
            }
          })
        } else {
          wx.showToast({
            title: rep.data.message,
            icon: 'none'
          })
        }
      })
    } else {
      _this.setData({
        phone_number: e.detail.value
      })
    }
  },
  //获取店员列表
  onStore() {
    var _this = this
    let url = app.link.appraisal,
      data = {}
    com.link(url, data, function(rep) {
      console.log(rep)
      let url = app.link.storePeople + rep.data.response.response.store + '.st',
        data = {}
      com.link(url, data, function(rep) {
        console.log(rep)
        setTimeout(() => {
          _this.setData({
            statusd: 0
          })
        }, 300)
        _this.setData({
          list: rep.data.data.users,
        })
      }, 'GET')
    }, 'GET')
  },
  onReady: function() {},
  onShow: function() {
    var _ = this
    _.onStore()
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {}
})